fix(config): restrict censys.cfg to owner-only permissions - #719
Draft
Zack (Zackaryia) wants to merge 1 commit into
Draft
fix(config): restrict censys.cfg to owner-only permissions#719Zack (Zackaryia) wants to merge 1 commit into
Zack (Zackaryia) wants to merge 1 commit into
Conversation
Create ~/.config/censys with mode 0700 and write censys.cfg with mode 0600 instead of inheriting the process umask, and tighten permissions on pre-existing files/directories on rewrite. Under the default umask of 022 the config file was previously world-readable (0644), exposing api_secret and asm_api_key to other local users (CWE-276). Fixes GHSA-xm52-gr3v-ffpq (IIP-22870)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
write_config()created~/.config/censysand wrotecensys.cfgwithout an explicit mode, so permissions were governed solely by the process umask. Under the common default umask of022, the config file — which holdsapi_id,api_secret, andasm_api_keyin plaintext — ended up world-readable (0644) and the directory world-traversable (0755). On shared hosts, any local unprivileged user could read the victim's live API credentials (CWE-276, Incorrect Default Permissions).This change hardens
write_config()so it no longer inherits the ambient umask:0700(and chmod'd to0700if it already exists).0600via anopenerthat passes0o600toos.open(), and any pre-existing file is chmod'd to0600before credentials are written to it.Fixes GHSA-xm52-gr3v-ffpq (internal ticket: IIP-22870).
Changes
censys/common/config.py:write_config()now creates the config directory0700, creates the config file0600, and tightens permissions on pre-existing files/directories on rewrite.tests/cli/test_config.py: adjusted existing assertions for the newopen()/makedirs()calls and addedtest_write_config_restricts_permissions, a real-filesystem test verifying0700/0600for both fresh writes and rewrites over loose-permission files.Checklist